//
//  FuncViewController.m
//  LibDemo
//
//  Created by Gikki Ares on 2020/9/5.
//

#import "JsRequestManagerTestController.h"
#import <JsUtilitySdk/JsMenuView.h>
//#import "MenuView.h"
#import <JsUtilitySdk/JsRequestManager.h>
#import <JsUtilitySdk/JsDisplayManager.h>
#import <JsUtilitySdk/JsGeometryManager.h>
#import <JsUtilitySdk/JsRequestManager.h>
#import <JsUtilitySdk/JsColorManager.h>

@interface JsRequestManagerTestController ()<JsMenuViewDelegate>
{
	JsMenuView * mMenuView;
	UITextView * mtv;
}

@end

@implementation JsRequestManagerTestController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
	
	self.view.backgroundColor = [UIColor whiteColor];
	[self setupUi];
}

- (void)setupUi {
	if(!mMenuView) {
		mMenuView = [[JsMenuView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)];
		mMenuView.delegate = self;
		JsDisplayStyle * style = [JsDisplayStyle defaulStyle];
		style.mb_isMaskCancellable = NO;
		style.displayPosition = JsDisplayPositionBottom;
		[mMenuView displayInView:self.view withDisplayStyle:style undisplayCompletionHandler:nil];
	}
	
	if(!mtv) {
		mtv = [[UITextView alloc]initWithFrame:CGRectMake(0, 100, JsGeometryManager.screenWidth, 500)];
		mtv.backgroundColor = [JsColorManager morandi_red];
		[self.view addSubview:mtv];
	}
}

- (void)viewDidLayoutSubviews {
	[super viewDidLayoutSubviews];
}

# pragma mark 4 Delegate
//- (JsMenuViewStyle *)jsMenuViewSetStyle:(JsMenuView *)view {
//
//}

- (NSArray<JsMenuItemVm *> *)jsMenuViewSetDatasource:(JsMenuView *)view {
	return @[
		[[JsMenuItemVm alloc] initWithTitle:@"Get请求" imageName:nil],
		[[JsMenuItemVm alloc] initWithTitle:@"Post请求" imageName:nil]
	];
}


- (void)jsMenuView:(JsMenuView *)view clickMenuAtIndex:(int)index vm:(nonnull JsMenuItemVm *)vm {
	switch (index) {
		case 0:{
			[self testGet];
			break;
		}
		case 1: {
			[self testPost];
			break;
		}
		default:
			break;
	}
}

- (void)testGet {
	//// https://169.vgemv.com:59091/live_cms/apiserver/categoryLiveRooms.action?categoryId=37
	JsRequestConfig * config = [[JsRequestConfig alloc]initWithMethod:JsRequestMethodGet requestBodyInputType:JsRequestBodyInputTypeMapToJson responseBodyOutputType:JsResponseBodyOutputTypeJsonToMap];
	config.isGenerateDetailString = @(YES);
	config.interfaceUrlString = @"https://169.vgemv.com:59091/live_cms/apiserver/categoryLiveRooms.action";
	config.requestBodyInput = @{
		@"categoryId":@(37)
	};
	[[JsRequestManager sharedInstance] invokeDataTaskWithConfig:config completionHandler:^(int responseState, id  _Nullable resultObject, NSString * _Nullable error, JsRequestInfo * _Nullable detailInfo) {
		self->mtv.text = [detailInfo toString];
	}];
}

- (void)testPost {
	JsRequestConfig * config = [[JsRequestConfig alloc]initWithMethod:JsRequestMethodPost requestBodyInputType:JsRequestBodyInputTypeMapToJson responseBodyOutputType:JsResponseBodyOutputTypeJsonToMap];
	config.isGenerateDetailString = @(YES);
	config.interfaceUrlString = @"https://169.vgemv.com:59091/live_cms/apiserver/categoryLiveRooms.action";
	config.requestBodyInput = @{
		@"categoryId":@(37)
	};
	[[JsRequestManager sharedInstance] invokeDataTaskWithConfig:config completionHandler:^(int responseState, id  _Nullable resultObject, NSString * _Nullable error, JsRequestInfo * _Nullable detailInfo) {
		self->mtv.text = [detailInfo toString];
	}];
}

@end
